package com.zcc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class RestFulController {
    //定义网页地址为add，传入参数的方式是add/参数a的值/参数b的值
    //@RequestMapping("add/{a}/{b}")
    //以Get的方法进行请求
    @GetMapping("add/{a}/{b}")
    //使用注解@PathVariable的参数才能做完被传入的参数
    public String test1(@PathVariable int a, @PathVariable int b, Model m){
        int res = a+b;
        m.addAttribute("msg","test1"+res);
        return "hello";
    }
    //以Post的方法进行请求
    @PostMapping("add/{a}/{b}")
    //使用注解@PathVariable的参数才能做完被传入的参数
    public String test2(@PathVariable int a, @PathVariable int b, Model m){
        int res = a+b;
        m.addAttribute("msg","test2"+res);
        return "hello";
    }
    @RequestMapping("t3")
    public String test3(Model m){
        m.addAttribute("msg","test3");
        return "forward:/index.jsp";
        //return "redirect:/WEB-INF/jsp/hello.jsp";
    }
}
